let app = getApp()
Component({
    properties: {
 
      },
      data:{
        siteDomain:app.globalData.siteDomain,
        page:1,
        video_num:0
      },
    lifetimes: {
        attached: function () {
          var user_id=wx.getStorageSync('user_id');
          if(user_id=='')
          {
             this.setData({
                pagetype:'login'
             })
          }else{
            var that=this
            wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Staff_getStaffInfo',
                staff_id:wx.getStorageSync('staff_bind_id'),
                user_id:wx.getStorageSync('user_id')
              },
              success: function(res) {
                that.setData({
                  info:res.data.info,
                  is_follow:res.data.info.is_follow
                })
              }
            })
          }
        
        
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Staff_myWork',
              page:that.data.page
            },
            success: function(res) {
              that.setData({
                page:parseInt(that.data.page)+1,
                list:res.data.info,
                video_num:res.data.video_num
              })
            }
          })
       }
      },
    methods: {
      onReachBottom: function () {
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Staff_myWork',
            page:that.data.page
          },
          success: function(res) {
            var list=that.data.list
            if(res.data.info.length>0){
              list=list.concat(res.data.info)
              that.setData({
                page:parseInt(that.data.page)+1,
                list:list
              })
            }
          }
        })
      },
      chat:function(){
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=chat'
        })
      },
      focus:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Staff_follow',
            staff_id:wx.getStorageSync('staff_bind_id'),
            user_id:wx.getStorageSync('user_id')
          },
          success: function(res) {
            wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Staff_getStaffInfo',
                staff_id:wx.getStorageSync('staff_bind_id')
              },
              success: function(res) {
                that.setData({
                  info:res.data.info,
                  is_follow:1
                })
              }
            })
          }
        })
      },
      return:function(){
        wx.redirectTo({
          url: '/yb_shopv2/entry/video-market/index',
        })
      },
      home:function(e){
          const  id=e.currentTarget.dataset.id;
           wx.redirectTo({ 
             url: '/yb_shopv2/entry/video-market/index?id='+id,
           })
      },
      copyText:function(e){
        if(typeof(e.currentTarget.dataset.text)!='undefined'){
          wx.setClipboardData({
            data: e.currentTarget.dataset.text,
            success: function (res) {
              wx.getClipboardData({
                success: function (res) {
                  wx.showToast({
                    title: '复制成功'
                  })
                }
              })
            }
          })
        }else{
          wx.showToast({
            icon:'none',
            title: '暂无微信'
          })
        }
      },
      btnTelPhone:function(e){
        if(e.currentTarget.dataset.key.length>0){
          var phone=e.currentTarget.dataset.key
          wx.showModal({
            title: "是否要拨打这个电话？",
            content:phone,
            success: function(e) {
                e.confirm ?     wx.makePhoneCall({
                  phoneNumber:phone,
                  success:function(){
                    console.log('拨打成功')
                  },
                  fail:function(){
                    wx.showToast({
                      icon:'none',
                      title: '取消拨打'
                    })
                  }
                })   : e.cancel && console.log("用户点击取消");
            }
        })
        }else{
          wx.showToast({
            icon:'none',
            title: '暂无电话'
          })
        }
      }
    }
});
